package com.example.jdbc_demo.util;

import java.sql.DriverManager;
import java.sql.SQLException;

public class jdbc_demo {
    static {
        try{
            Class.forName("com.mysql.cj.jdbc.Driver");
        }catch (ClassNotFoundException e){
            e.printStackTrace();
        }
    }
    public static java.sql.Connection getConnection(){
        try{
            return DriverManager.getConnection("jdbc:mysql://localhost:3306/data", "root", "123456");
        }catch (SQLException e){
            e.printStackTrace();
        }
        return null;
    }

    public static java.sql.Statement getStatement(){
        try{
            return getConnection().createStatement();
        }catch (SQLException e){
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        try {
            java.sql.Statement statement = getStatement();
            java.sql.ResultSet resultSet = statement.executeQuery("select * from details");
            while (resultSet.next()){
                System.out.println(resultSet.getString("province"));
                System.out.println(resultSet.getString("confirm"));
            }
            resultSet.close();

        }catch (SQLException e){
            e.printStackTrace();
        }
    }

}
